package com.mall.user.services;

import com.mall.user.ILoginService;
import com.mall.user.dto.CheckAuthRequest;
import com.mall.user.dto.CheckAuthResponse;
import com.mall.user.utils.JwtTokenUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

@Component
@Service(interfaceClass = ILoginService.class)
public class ILoginServiceImpl implements ILoginService {
    @Override
    public CheckAuthResponse validToken(CheckAuthRequest request) {
        CheckAuthResponse checkAuthResponse = new CheckAuthResponse();


        String token = request.getToken();
        String msg = null;
        try {
            msg = JwtTokenUtils.builder().token(token).build().freeJwt();
        }catch (Exception e){
            checkAuthResponse.setCode("003004");
            checkAuthResponse.setMsg("用户信息不合法");
            return checkAuthResponse;
        }
        checkAuthResponse.setUserinfo(msg);
        checkAuthResponse.setCode("000000");
        checkAuthResponse.setMsg("成功");
        return checkAuthResponse;
    }
}
